package org.noobie.photopicker.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.noobie.photopicker.R;
import org.noobie.photopicker.entity.Album;
import org.noobie.photopicker.util.LoadUtils;

public class AlbumItem extends LinearLayout {

	private ImageView ivAlbum, ivIndex;
	private TextView tvName, tvCount;

	public AlbumItem(Context context) {
		this(context, null);
	}

	public AlbumItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.layout_album, this, true);

		ivAlbum = findViewById(R.id.iv_album_la);
		ivIndex = findViewById(R.id.iv_index_la);
		tvName = findViewById(R.id.tv_name_la);
		tvCount = findViewById(R.id.tv_count_la);
	}

	public AlbumItem(Context context, AttributeSet attrs, int defStyle) {
		this(context, attrs);
	}

	public void setAlbumImage(String path) {
		LoadUtils.loadImage(getContext(),"file://" + path,ivAlbum);
	}

	public void update(Album album) {
		setAlbumImage(album.getRecent());
		setName(album.getName());
		setCount(album.getCount());
		isCheck(album.isChecked());
	}

	public void setName(CharSequence title) {
		tvName.setText(title);
	}

	public void setCount(int count) {
		tvCount.setHint(count + "");
	}

	public void isCheck(boolean isCheck) {
		ivIndex.setVisibility(isCheck ? View.VISIBLE : View.GONE);
	}

}
